package com.client.rule;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.TreeItem;

public class RootItem extends TreeItem{
	
	HorizontalPanel panel = new HorizontalPanel();	
	private TextBox textBox = new TextBox();
	private Button saveButton = new Button("Sauver");
	
	public RootItem() {
		super();				
		saveButton.addClickHandler(new ClickHandler(){
		public void onClick(ClickEvent e) {
		        if (!textBox.getText().isEmpty()) {		        			        		
		        	RootItem.this.setText(textBox.getText());
		        	
		        }
		      }
		 });
		panel.add(textBox);
		panel.add(saveButton);
		setWidget(panel);		
	}
	
	public RootItem(String name) {
		this();			
		textBox.setValue(name);
		setText();
	}
	
	
	
	public void setText(){		
		super.setText(textBox.getValue());		
	}
	
	public void showWidget(){
		textBox.setValue(getText());
		setWidget(panel);		
	}

}
